home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
os2
/
ext2_200.zip
/
EXT2_SRC.ZIP
/
32BITS
/
EXT2-OS2
/
FSD32
/
FS32_WRI.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-09-21
|
7KB
|
156 lines
//
// $Header: D:/32bits/ext2-os2/fsd32/RCS/fs32_write.c,v 1.1 1996/09/21 22:25:48 Willm Exp Willm $
//
// 32 bits Linux ext2 file system driver for OS/2 WARP - Allows OS/2 to
// access your Linux ext2fs partitions as normal drive letters.
// Copyright (C) 1995, 1996 Matthieu WILLM
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifdef __IBMC__
#pragma strings(readonly)
#endif
#define INCL_DOS
#define INCL_DOSERRORS
#define INCL_NOPMAPI
#include <os2.h>
#include <os2/types.h>
#include <os2/StackToFlat.h>
#include <linux/fs.h>
#include <os2/os2proto.h>
#include <os2/fsd32.h>
#include <os2/DevHlp32.h>
#include <os2/log.h>
#include <os2/trace.h>
#include <os2/errors.h>
#include <os2/files.h>
#include <os2/volume.h>
#include <linux/fs_proto.h>
#include <linux/stat.h>
#include <os2/filefind.h>
/*
* struct fs32_write_parms {
* unsigned short IOflag;
* PTR16 pLen;
* PTR16 pData;
* PTR16 psffsd;
* PTR16 psffsi;
* };
*/
int FS32ENTRY fs32_write(struct fs32_write_parms *parms) {
char *pData;
struct sffsi32 *psffsi;
union sffsd32 *psffsd;
int rc;
unsigned short *pLen;
int rc2, err;
unsigned long BytesWritten;
char lock[12];
unsigned long PgCount;
parms = __StackToFlat(parms);
if ((rc = DevHlp32_VirtToLin(parms->psffsi, __StackToFlat(&psffsi))) == NO_ERROR) {
if ((rc = DevHlp32_VirtToLin(parms->psffsd, __StackToFlat(&psffsd))) == NO_ERROR) {
if ((rc = DevHlp32_VirtToLin(parms->pData, __StackToFlat(&pData))) == NO_ERROR) {
if ((rc = DevHlp32_VirtToLin(parms->pLen, __StackToFlat(&pLen))) == NO_ERROR) {
if (trace_FS_WRITE) {
kernel_printf("FS_WRITE( len = %u ) pre-invocation", *pLen);
}
/*
* Locks the user buffer to check read access and to prevent other threads from freing it
* behind us when we are sleeping. (this is a long term verify lock)
*/
if (Read_Write) {
rc = DevHlp32_VMLock(VMDHL_LONG | VMDHL_VERIFY, pData, *pLen, (void *)-1, __StackToFlat(lock), __StackToFlat(&PgCount));
if ((rc == NO_ERROR) || (rc == ERROR_NOBLOCK)) {
/*
* Gets the file structure from psffsd
*/
if ((psffsd->f) && (psffsd->f->f_magic == FILE_MAGIC)) {
/*
* Tests if it is a regular file
*/
if (S_ISREG(psffsd->f->f_inode->i_mode)) {
/*
* If the file position in psffsi is not consistent with the
* one in the file structure in psffsd, something went wrong => panic
*/
if (psffsi->sfi_position == (unsigned long)psffsd->f->f_pos) {
/*
* Now we do the actual write operation
*/
err = VFS_write(psffsd->f, pData, (loff_t)*pLen, __StackToFlat(&BytesWritten));
*pLen = (unsigned short)BytesWritten;
psffsi->sfi_tstamp |= ST_PWRITE;
psffsi->sfi_size = psffsd->f->f_inode->i_size;
psffsi->sfi_position = psffsd->f->f_pos;
rc = err;
} else {
kernel_printf("FS_WRITE( %lu ) very weird : psffsi->sfi_position != psffsd->f->f_pos : %ld %ld", psffsd->f->f_inode->i_ino, psffsi->sfi_position, psffsd->f->f_pos);
*pLen = 0;
rc = ERROR_WRITE_FAULT; // Maybe we should FSH_INTERR ?
} /* sfi_position != f_pos */
} else {
kernel_printf("Can't FS_WRITE( %lu ) - Not a regular file", psffsd->f->f_inode->i_ino);
*pLen = 0;
rc = ERROR_ACCESS_DENIED;
} /* !S_ISREG */
} else {
kernel_printf("FS_WRITE() - psffsd->f is NULL");
rc = ERROR_INVALID_PARAMETER;
} /* psffsd->f = NULL */
if ((rc2 = DevHlp32_VMUnlock(__StackToFlat(lock))) == NO_ERROR) {
/*
* Nothing else to do
*/
} else {
kernel_printf("FS_WRITE : VMUnlock() returned %d", rc2);
rc = rc2;
} /* VMUnlock failed */
} else {
kernel_printf("FS_WRITE : LockUserBuffer() returned %d", rc);
} /* LockUserBuffer() failed */
} else {
/*
* ext2-os2.ifs in read only mode (-rw not set on the IFS command line)
*/
kernel_printf("ERROR ! FS_WRITE() called and write access not enabled");
rc = ERROR_WRITE_PROTECT;
} /* Read_Write = 0 */
if (trace_FS_WRITE) {
kernel_printf("FS_WRITE( len = %u ) post-invocation (rc = %d)", *pLen, rc);
}
}
}
}
}
return rc;
}